import React, {useRef} from 'react';
import {
    useNavigate
} from "react-router-dom";
import store from "../store";
import {addGoods} from "../store/slice/goods";

function AddGoods(props) {
    const goodsNameRef = useRef();
    const goodsPriceRef = useRef();
    const navigate = useNavigate();
    return (
        <form onSubmit={e=>{
            e.preventDefault();
            store.dispatch(addGoods({
                goodsName:goodsNameRef.current.value.trim(),
                goodsPrice:goodsPriceRef.current.value.trim()/1
            }));
            navigate("/goodsList");

        }}>
            <p>商品名称：<input ref={goodsNameRef} type="text"/></p>
            <p>商品价格：<input ref={goodsPriceRef} type="number"/></p>
            <button>提交</button>
        </form>
    );
}

export default AddGoods;